package com.luom.fsp.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单状态枚举枚举
 *
*/
public enum OrderStatusEnum {

    PENDING("待支付", "pending"),
    PAID("已支付", "paid"),
    SHIPPED("已发货", "shipped"),
    COMPLETED("已完成", "completed"),
    CANCELLED("已取消", "cancelled"),
    REFUNDED("已退款", "refunded");


    /**
     * pending:待支付，paid:已支付，shipped:已发货，completed:已完成，cancelled:已取消，refunded:已退款
     */

    private final String text;

    private final String value;

    OrderStatusEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static OrderStatusEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (OrderStatusEnum anEnum : OrderStatusEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }
}
